# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=t1utils
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.41
pkgrel=1
pkgdesc="A collection of simple Type 1 font manipulation programs (mingw-w64)"
arch=('any')
url="https://www.lcdf.org/~eddietwo/type/#t1utils"
license=('custom')
source=("https://www.lcdf.org/~eddietwo/type/${_realname}-$pkgver.tar.gz"
        "memmem-decl.patch"
        "LICENSE")
sha512sums=('b532d3af38a73903a512eb1297ba7510747dcbe8362acc4a0f20f2a3c786d82d8f5b22997ed3867114f33153a34cdd71c4c8e6a093db3cecc3825b6e4725a00b'
            '573a15133e8227100820039aaf5dea12d038674dd486510a38647e9f500c9de2c16034d99c8b26444f6c7253fe788833aa6dbd3f46be389bc1ca1b031deb51c8'
            '82dbc206391a9f9116038be74360455c960ddb76e35fdeb123044f74c74014223c3b35d7f1894ae7224c7a9e091acc1ff00df2a43d38a856b4f75988fb4dbd3e')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  # FS#57999 and https://github.com/kohler/t1utils/issues/8
  apply_patch_with_msg "memmem-decl.patch"
  autoreconf -fiv
}

build() {
  cd "${srcdir}"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"

  install -D -m644 "${srcdir}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
